<?php
/**
 * Created by PhpStorm.
 * User: wanglong
 * Date: 2017/12/17
 * Time: 17:04
 */

namespace app\common\services;

//只封装通用方法
use yii\helpers\Html;

class UtilService
{
    public static function getIP()
    {
        //server中存在http_x_forwarded_for说明设置了反向代理
        if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        return $_SERVER['REMOTE_ADDR'];
    }

    //防止xss攻击
    public static function encode($display)
    {
        return Html::encode($display);
    }

    //获取系统的路径
    public static function getRootPath()
    {
        return dirname(\Yii::$app->vendorPath);
    }
}